package vista;

import modelo.Empleado;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.bindings.ObservableProperty;
import org.uqbar.arena.bindings.PropertyAdapter;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.Selector;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.windows.Dialog;
import org.uqbar.arena.windows.WindowOwner;
import org.uqbar.lacar.ui.model.ListBuilder;
import org.uqbar.lacar.ui.model.bindings.Binding;

import database.Tienda;
import applicationModels.AgregarExcepcion;

public abstract class AgregarAbstractExcepcionWindow extends Dialog<AgregarExcepcion> {

	private static final long serialVersionUID = 1L;

	public AgregarAbstractExcepcionWindow(WindowOwner owner) {
		super(owner, new AgregarExcepcion());
		this.setTaskDescription("");
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		Panel formPanel=new Panel(mainPanel);
		formPanel.setLayout(new ColumnLayout(2));
		new Label(formPanel).setText("Empleado:");
		Selector<Empleado> selectorEmpleado=new Selector<Empleado>(formPanel)
			.allowNull(false);
		selectorEmpleado.bindValueToProperty("empleadoElegido");
		
		Binding<ListBuilder<Empleado>> itemsBinding = selectorEmpleado.bindItems(new ObservableProperty(Tienda.getInstance(), "empleados"));
		itemsBinding.setAdapter(new PropertyAdapter(Empleado.class, "identificacionCompleta"));
		
		new Label(formPanel).setText("Fecha:");
		new TextBox(formPanel)
			.setWidth(100)
			.bindValueToProperty("fechaExcepcion")
			.setTransformer(new FechaToStringAdapter());
	}
	
	@Override
	protected void addActions(Panel actionsPanel) {
		new Button(actionsPanel)
		.setCaption("Aceptar")
		.onClick(new MessageSend(this, "accept"))
		.setAsDefault()
		.disableOnError();

		new Button(actionsPanel)
			.setCaption("Cancelar")
			.onClick(new MessageSend(this, "cancel"));		
	}
	
	@Override
	public void accept(){
		super.accept();
	}

}
